/*
	Copyright (C) 2013 Pontificia Universidad Catolica del Peru
	contact: http://avatar.inf.pucp.edu.pe/realidad-aumentada/
	address contact: Av. Universitaria 1801, San Miguel, Lima-Peru.
	
	This file is part of UbicAR PUCP.

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with This program.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Authors: Alvaro Roger Agüero Sánchez, Rodolfo Javier Galvez Meza
	Pontificia Universidad Catolica del Peru
	Departamento de Ingeniería
*/

package org.grupoavatar.guiaubicua.howto;

import org.grupoavatar.guiaubicua.R;

import android.app.Activity;
import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class CustomPagerAdapter extends PagerAdapter {
	private Activity context;
	public final static int NUM_PAGINAS=9;
	public CustomPagerAdapter(Activity activity) {
		context = activity;
	}

	public Object instantiateItem(final View collection, int position) {

		LayoutInflater inflater = (LayoutInflater) collection.getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		int resId = 0;
		switch (position) {
			case 0: {
				resId = R.layout.page_1;
				break;
			}
			case 1: {
				resId = R.layout.page_2;
				break;
			}
			case 2: {
				resId = R.layout.page_3;
				break;
			}
			case 3: {
				resId = R.layout.page_4;
				break;
			}
			case 4: {
				resId = R.layout.page_5;
				break;
			}
			case 5: {
				resId = R.layout.page_6;
				break;
			}
			case 6: {
				resId = R.layout.page_7;
				break;
			}
			case 7: {
				resId = R.layout.page_8;
				break;
			}
			case 8: {
				resId = R.layout.page_9;
				break;
			}
		}

		View view = inflater.inflate(resId, null);
		
		// Workaround
//		if (position == 0) {
//			Button buttonBlue = (Button) view.findViewById(R.id.buttonCerrar);
//			buttonBlue.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					//Toast.makeText(v.getContext(), "Blue screen", Toast.LENGTH_SHORT).show();		
//					context.finish();
//				}
//			});
//		}

		((ViewPager) collection).addView(view, 0);

		return view;
	}

	@Override
	public void destroyItem(View arg0, int arg1, Object arg2) {
		((ViewPager) arg0).removeView((View) arg2);
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == ((View) arg1);

	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public int getCount() {
		return CustomPagerAdapter.NUM_PAGINAS;
	}
}